package cn.lisens.sensitive;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

public class PhoneDesensitizeSerializer extends StdSerializer<String> {

	private static final long serialVersionUID = 1L;
	
	public PhoneDesensitizeSerializer() {
		super(String.class);
	}

	@Override
	public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {
		// 示例：手机号脱敏 (181****1234)
        if (value != null && value.length() > 7) {
            String masked = value.substring(0, 3) + "****" + value.substring(value.length() - 4);
            gen.writeString(masked);
        } else {
            gen.writeString(value);
        }
	}

}
